/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entity;

import java.io.Serializable;
import javax.persistence.Entity;
import java.util.*;
import javax.persistence.CascadeType;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Temporal;
import type.PickingOrderStatus;

/**
 *
 * @author Andy
 */
@Entity(name = "PickingOrder")
public class PickingOrderEntity extends DataObjectEntity implements Serializable {

    @ManyToOne
    private ProductEntity product;
    private PickingOrderStatus status;
    //Collection of products(by cases) to pick
    @ManyToOne
    private PickListEntity pickList;
    
    @OneToOne(mappedBy = "pickingOrder",  cascade = {CascadeType.ALL})
    private ReservationEntity reservation;
    
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date pickDate;
    @OneToMany
    private Collection<LocationQuantityEntity> locationToQuantity = new ArrayList<LocationQuantityEntity>();

    public PickingOrderEntity() {
        super();
    }

    public ReservationEntity getReservation() {
        return reservation;
    }

    public void setReservation(ReservationEntity reservation) {
        this.reservation = reservation;
    }

    public ProductEntity getProduct() {
        return product;
    }

    public void setProduct(ProductEntity product) {
        this.product = product;
    }

    public PickListEntity getPickList() {
        return pickList;
    }

    public void setPickList(PickListEntity pickList) {
        this.pickList = pickList;
    }

    public PickingOrderStatus getStatus() {
        return status;
    }

    public void setStatus(PickingOrderStatus status) {
        this.status = status;
    }

    public Date getPickDate() {
        return pickDate;
    }

    public void setPickDate(Date pickDate) {
        this.pickDate = pickDate;
    }
    private int locationToQuantitySize;

    public int getLocationToQuantitySize() {
        if (getLocationToQuantity() != null) {
            locationToQuantitySize = getLocationToQuantity().size();
            return locationToQuantitySize;
        }
        return 0;
    }

    public void setLocationToQuantitySize(int locationToQuantitySize) {
        this.locationToQuantitySize = locationToQuantitySize;
    }

    public Collection<LocationQuantityEntity> getLocationToQuantity() {
         List<LocationQuantityEntity> lqeList = new ArrayList<LocationQuantityEntity>(locationToQuantity);
      for(LocationQuantityEntity lqe : lqeList){
          if(lqe.isArchived()==true)
              locationToQuantity.remove(lqe);
      }
        return locationToQuantity;
    }

    public void setLocationToQuantity(Collection<LocationQuantityEntity> locationToQuantity) {
        this.locationToQuantity = locationToQuantity;
    }

    @Override
    public String childToString() {
        return "PickingOrderEntity{" + "product=" + product + ", status=" + status + ", pickList=" + pickList + ", reservation=" + reservation + ", pickDate=" + pickDate + ", locationToQuantity=" + locationToQuantity + '}';
    }
}
